﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Collections;

/// <summary>
/// Summary description for GiftBUS
/// </summary>
public class GiftBUS
{
    GiftDAL giftDAL = new GiftDAL();
    ArrayList gh;
    
    
	public GiftBUS()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public DataTable returnAllGift() {
        return giftDAL.getAllGift();
    }
    public DataTable returnGiftByCID(int id) {
        return giftDAL.getGiftByCID(id);
    }
    public bool updateStatusGift(string id) {
        return giftDAL.updateStatusGift(id);
    }

    public DataTable returnGiftByID(string id) {
        return giftDAL.getGiftByID(id);
    }
    public bool insertGift(string id, string name, float price, string details, string image, int cid) {
        return giftDAL.insertGift(id,name,price,details,image,cid);
    }
    public void AddCart(List<Gift> lsGift) {
        gh = (ArrayList)HttpContext.Current.Session["GioHang"];
        foreach (Gift gift in lsGift) {
            foreach (ShoppingCart sp in gh)
            {
                if (sp.Id.Equals(gift.Id))
                {
                    int slNew = sp.Number + 1;
                    ShoppingCart h = new ShoppingCart(sp.Id, sp.Image, sp.Name, slNew, sp.Price);
                    gh.Remove(sp);
                    gh.Add(h);
                    return;
                }
            }
            ShoppingCart h1 = new ShoppingCart(gift.Id, gift.Image, gift.Name, 1, gift.Price);
            gh.Add(h1);
            HttpContext.Current.Session["GioHang"] = gh;
            HttpContext.Current.Session["SLItem"] = gh.Count;
        }
    }

    public bool updateGift(string id, string name, float price, string details, string image, int cid) {
        return giftDAL.updateGift(id, name, price, details, image, cid);
    }
}